diff options
Diffstat (limited to 'src/android/app/src/main/jni/native.cpp')
-rw-r--r-- | src/android/app/src/main/jni/native.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index b10c55a45..a7321af2a 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp @@ -38,6 +38,8 @@ #include "core/frontend/applets/software_keyboard.h" #include "core/frontend/applets/web_browser.h" #include "core/hid/hid_core.h" +#include "core/hid/emulated_controller.h" +#include "core/hid/hid_types.h" #include "core/hle/service/acc/profile_manager.h" #include "core/hle/service/am/applet_ae.h" #include "core/hle/service/am/applet_oe.h" @@ -274,6 +276,60 @@ public: m_rom_metadata_cache.clear(); } + bool IsHandheldOnly(){ + const auto npad_style_set = m_system.HIDCore().GetSupportedStyleTag(); + + if (npad_style_set.fullkey == 1) { + return false; + } + + if (npad_style_set.handheld == 0) { + return false; + } + + return !Settings::values.use_docked_mode.GetValue(); + } + + void SetDeviceType(int index, int type){ + auto controller = m_system.HIDCore().GetEmulatedControllerByIndex(index); + controller->SetNpadStyleIndex(static_cast<Core::HID::NpadStyleIndex>(type)); + } + + void OnGamepadConnectEvent(int index){ + auto controller = m_system.HIDCore().GetEmulatedControllerByIndex(index); + + // Ensure that player1 is configured correctly and handheld disconnected + if(controller->GetNpadIdType() == Core::HID::NpadIdType::Player1){ + auto handheld = m_system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Handheld); + + if(controller->GetNpadStyleIndex() == Core::HID::NpadStyleIndex::Handheld) { + handheld->SetNpadStyleIndex(Core::HID::NpadStyleIndex::ProController); + controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::ProController); + handheld->Disconnect(); + } + } + + // Ensure that handheld is configured correctly and player 1 disconnected + if(controller->GetNpadIdType() == Core::HID::NpadIdType::Handheld){ + auto player1 = m_system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1); + + if(controller->GetNpadStyleIndex() != Core::HID::NpadStyleIndex::Handheld) { + player1->SetNpadStyleIndex(Core::HID::NpadStyleIndex::Handheld); + controller->SetNpadStyleIndex(Core::HID::NpadStyleIndex::Handheld); + player1->Disconnect(); + } + } + + if(!controller->IsConnected()){ + controller->Connect(); + } + } + + void OnGamepadDisconnectEvent(int index){ + auto controller = m_system.HIDCore().GetEmulatedControllerByIndex(index); + controller->Disconnect(); + } + SoftwareKeyboard::AndroidKeyboard* SoftwareKeyboard() { return m_software_keyboard; } @@ -440,11 +496,45 @@ jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_isRunning([[maybe_unused]] JNIEnv return static_cast<jboolean>(EmulationSession::GetInstance().IsRunning()); } +jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_isHandheldOnly([[maybe_unused]] JNIEnv* env, + [[maybe_unused]] jclass clazz) { + return EmulationSession::GetInstance().IsHandheldOnly(); +} + +jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_setDeviceType([[maybe_unused]] JNIEnv* env, + [[maybe_unused]] jclass clazz, + jint j_device, + jint j_type) { + if (EmulationSession::GetInstance().IsRunning()) { + EmulationSession::GetInstance().SetDeviceType(j_device, j_type); + } + return static_cast<jboolean>(true); +} + +jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_onGamePadConnectEvent([[maybe_unused]] JNIEnv* env, + [[maybe_unused]] jclass clazz, + jint j_device) { + if (EmulationSession::GetInstance().IsRunning()) { + EmulationSession::GetInstance().OnGamepadConnectEvent(j_device); + } + return static_cast<jboolean>(true); +} + +jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_onGamePadDisconnectEvent([[maybe_unused]] JNIEnv* env, + [[maybe_unused]] jclass clazz, + jint j_device) { + if (EmulationSession::GetInstance().IsRunning()) { + EmulationSession::GetInstance().OnGamepadDisconnectEvent(j_device); + } + return static_cast<jboolean>(true); +} jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_onGamePadButtonEvent([[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz, [[maybe_unused]] jint j_device, jint j_button, jint action) { if (EmulationSession::GetInstance().IsRunning()) { + // Ensure gamepad is connected + EmulationSession::GetInstance().OnGamepadConnectEvent(j_device); EmulationSession::GetInstance().Window().OnGamepadButtonEvent(j_device, j_button, action != 0); } |